layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;

	    form.verify({
	        title : function(val){
	            if(val == ''){
	                return "文章标题不能为空";
	            }
	        },
	        abstract:function(val){
	            if(val == ''){
	                return "文章摘要不能为空";
	            }
	        }
	    });
	    //创建一个编辑器
	    var editIndex = layedit.build('news_content',{
	        height : 535,
	        // uploadImage : {
	        //     url : "../../json/newsImg.json"
	        // }
	    });
    
	    form.on("submit(editNotice)",function(data){
	        console.log(data);
	        var content = layedit.getContent(editIndex).split('<audio controls="controls" style="display: none;"></audio>')[0];  //文章内容
	        console.log(content);
	        $.ajax({
	            type: "POST",
	            headers: {
	                token :  $.cookie('tokenA')
	            },
	            url: api+"notice/modify",
	            data: {
	            	id:$(".id").val(),
	                title: $('.title').val(),
	                abstractContent: $('.abstract').val(),
	                type: data.field.type,
	                content: content
	            },
	            success: function(result){	            	
	            	console.log(result);
	            	if(result.code == 1){
	  		             top.layer.msg("通知修改成功！");
	    		         setTimeout(function(){
				           parent.location.reload();
				         },2000);
	            	}
	            }
	        });
	        return false;
	    });


})